<style scoped>
.content .w980 {
    padding: 0 0 30px 30px;
}

.nav-path {
    position: relative;
}

.nav-path ol {
    width: 100%;
    height: 36px;
}

.nav-path button.add-hsp-btn {
    position: absolute;
    top: 0;
    right: 0;
}

.nav-path ol li a {
    color: #444;
}

.nav-path ol li:last-child {
    color: #00CB8F;
}


/*机构列表*/

.org-list {
    width: 94%;
    min-height: 650px;
    overflow: hidden;
    margin: 0 3% 10%;
    position: relative;
}


/*机构列表*/

.list-tips {
    padding: 0;
    height: 36px;
    line-height: 36px;
    background: #F5F5F4 url(../../assets/img/list_tips.png) no-repeat 20px center;
    background-size: 4px 20px;
}

.list-tips span {
    float: left;
    font-size: 22px;
    height: 36px;
    line-height: 36px;
    margin-left: 36px;
    text-align: left;
}


/*医院列表*/

.form-group.limitManage {
    margin-bottom: 40px;
    min-height: 580px;
    height: auto!important;
}

.form-group.limitManage label,
.form-group.limitManage aside {
    float: left;
}

.form-group.limitManage aside {
    height: 580px;
    overflow: auto;
    border: 1px solid #E6E5E2;
}

.form-group.limitManage aside.limit-hospital {
    width: 25%;
    margin-left: 13px;
    margin-right: 32px;
}

.form-group.limitManage aside.limit-hospital .hospital-list ul li a {
    display: block;
    width: 100%;
    height: 30px;
    line-height: 30px;
    color: #666;
    font-size: 14px;
    text-indent: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.form-group.limitManage aside.limit-hospital .hospital-list ul li a:hover {
    color: #f00;
    text-decoration: none;
    background-color: #85D0F1;
}

.form-group.limitManage aside.limit-hospital-detail {
    width: 70%;
}

.form-group.limitManage .limit-title {
    padding: 0;
    height: 37px;
    line-height: 37px;
    background: #F8F8F7 url(../../assets/img/list_tips.png) no-repeat 20px center;
    background-size: 4px 20px;
}

.form-group.limitManage .limit-title span {
    float: left;
    font-size: 16px;
    height: 37px;
    line-height: 37px;
    margin-left: 34px;
}

table tbody {
    border-bottom: 1px solid #ddd;
}

table tr th,
table tr td {
    text-align: center;
    vertical-align: middle;
    padding: 15px 0!important;
}

.list-content table tr:nth-child(odd) {
    background-color: #fff;
}

.list-content table tr:nth-child(even) {
    background-color: #F6FBF8;
}

table tr td span.glyphicon {
    display: inline-block;
    width: 42px;
    height: 16px;
    font-size: 12px;
    text-align: right;
    margin-right: 5px;
    cursor: pointer;
    background-repeat: no-repeat!important;
    background-position: left center!important;
}

table tr td span:first-child {
    background: url(../../assets/img/watch.png) no-repeat left center;
    background-size: 17px 12px;
}

table tr td span:last-child {
    background: url(../../assets/img/delete.png) no-repeat left center;
    background-size: 14px;
}

.exp-mark {
    color: red;
    height: 100%;
    line-height: 100%;
    font-size: 14px;
    margin-right: 5px;
    display: inline-block;
}

.form-group label {
    font-weight: 400!important;
}


/*模态框基本设置*/

.modal-header {
    position: relative;
}

.modal-header .close {
    position: absolute;
    right: 28px;
    top: 50%;
    margin-top: -20px;
}


/*添加家医团队-编辑家医团队--模态框*/

.modal-dialog {
    width: 80%;
    height: 600px;
}

#add-teams-cover .modal-footer,
#edit-teams-cover .modal-dialog {
    border-top: 0;
}

.modal-body .form-group {
    text-align: center;
    display: block;
    margin-bottom: 18px;
    margin-top: 18px;
}

.modal-body .increase-team-per select,
.modal-body .increase-team-per input {
    width: 60%;
    display: inline-block;
}

.modal-body .form-group img {
    display: inline-block;
    width: 45%;
    text-align: left;
    text-indent: 10px;
    margin-left: 30px;
}

.modal-body .form-group-foot {
    text-align: center;
}

.modal-body .form-group label {
    width: 27%;
    text-align: right;
}

.modal-body .form-inline .form-control {
    width: 45%;
    text-align: left;
    text-indent: 10px;
    margin-left: 30px;
}

.modal-body .form-group .sim-explain-textarea {
    width: 45%;
    min-height: 122px;
    margin-left: 30px;
    overflow: auto;
    overflow-x: hidden;
    resize: none;
}

.modal-body .form-group button {
    width: 136px;
    height: 36px;
    color: #FFF;
    border-radius: 10px;
    outline: none;
}

.limit-title button {
    float: right;
    width: 118px;
    height: 32px;
    text-align: center;
    color: #fff;
    border-radius: 10px;
    background-color: #00A9FD;
    font-size: 16px;
    line-height: 32px;
    margin-right: 20px;
    /*margin-top: calc(50%-18px);*/
    margin-top: 1px;
    outline: none;
}

.modal-body .list-tips .team-label {
    float: left;
    height: 36px;
    line-height: 36px;
}

.modal-body .list-tips .new-per {
    float: right;
    height: 36px;
    line-height: 36px;
    color: #1AA9FD;
    margin-right: 46px;
    background: none;
}


/*科室详情信息*/

.dept-detail {
    margin: 20px;
}

.modal-pot {
    width: 60%;
    margin: 0 auto;
}

.ztree li span.button {
    background-position: -145px 0;
}

.start {
    font-size: 14px;
    color: red
}

#addDeptForm .modal-footer .form-group button {
    width: 106px;
}


/*信息填写不完整提示框*/

.msg-without-complete {
    z-index: 10200;
}

.msg-without-complete .modal-content {
    width: 40%;
    text-align: center;
    font-size: 16px;
    color: orangered;
    line-height: 100px;
    margin: 0 auto;
    top: 50%;
    -left: 50%;
    margin-top: -50px;
}

.modal-body .form-group button.cancel-btn {
    color: #00C782;
}

.depDescription {
    height: 68px!important;
    overflow: auto!important;
    resize: none;
}


/*删除服务提示*/

#delCoverTips {
    z-index: 10000;
}

#delCoverTips .modal-dialog {
    width: 34%;
}

.del-tips {
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 20px;
}

.del-tips span {
    color: #f00;
    padding: 0;
    display: inline-block;
    width: 18%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    vertical-align: middle;
}

.modal-footer .btn {
    width: 100px;
    margin-right: 20px;
    outline: none;
}

.modal-footer .btn.btn-primary {
    background-color: #00C782;
}


/*右键*/

div#rMenu {
    position: absolute;
    visibility: hidden;
    top: 0;
    background-color: #fafafa;
    text-align: left;
    padding: 2px;
    border: 1px solid #e6e6e6;
    padding: 5px
}

div#rMenu ul {
    margin-bottom: 0;
}

div#rMenu ul li {
    margin: 1px 0;
    padding: 5px 10px;
    cursor: pointer;
    list-style: none outside none;
}

div#rMenu ul li:nth-child(1) {
    background: url(../../assets/img/add2.png) no-repeat 10px center;
    padding-left: 35px;
    cursor: pointer;
    border-bottom: 1px solid #1DC499;
}

div#rMenu ul li:nth-child(2) {
    background: url(../../assets/img/dele3.png) no-repeat 10px center;
    padding-left: 35px;
    cursor: pointer;
}
</style>
<template>
    <div class="index clearafter">
        <!-- 头部组件 -->
        <header-component></header-component>
        <div class="content flex">
            <!-- 侧部导航组件 -->
            <div class="w220">
                <aside-component></aside-component>
            </div>
            <!-- 右部内容区 -->
            <div class="w980 flex_full">
                <!-- 路径导航 -->
                <nav class="nav-path">
                    <ol class="breadcrumb">
                        <li>科室管理</li>
                    </ol>
                </nav>
                <!-- 科室管理 -->
                <div class="fh-team-list">
                    <div class="form-group limitManage">
                        <!-- 社区机构列表 -->
                        <aside class="limit limit-hospital">
                            <!-- 标题 -->
                            <div class="limit-title">
                                <span>科室管理</span>
                            </div>
                            <div class="hospital-list">
                                <div class="content_wrap">
                                    <ul id="hospitalLists" class="ztree ff"></ul>
                                </div>
                            </div>
                        </aside>
                        <aside class="limit limit-hospital-detail">
                            <div class="limit-title">
                                <span>科室详情信息</span>
                            </div>
                            <div class="portlet-body form dept-detail">
                                <form class="form-horizontal" role="form" method="post" id="deptform">
                                    <div class="form-body">
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">机构名称</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" name="superiortitle" readonly id="pname" v-model="rootName">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">上级科室</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" name="superiortitle" readonly id="pname" v-model="prevDept" />
                                                <input type="hidden" class="form-control" name="superiortitle" readonly id="pname" v-model="deptDetailData.localId" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label"><span class="start">*</span>科室名称</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" id="name2" name="deptName" placeholder="科室名称" value="{{deptDetailData.deptName}}" v-model="deptDetailData.deptName" :disabled="eventOrg" maxlength="10" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label"><span class="start">*</span>科室代码(院内)</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" id="name2" name="localDeptId" placeholder="科室代码(院内)" value="{{deptDetailData.localDeptId}}" v-model="deptDetailData.localDeptId" :disabled="eventOrg" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label"><span class="start">*</span>科室类型</label>
                                            <div class="col-md-7">
                                                <select name="deptType" class="form-control" v-model="deptDetailData.deptType" :disabled="eventOrg">
                                                    <option v-for="item in dictionary.deptType" value="{{item.key}}">{{item.text}}</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">标准科室</label>
                                            <div class="col-md-7">
                                                <select name="standardDeptId" class="form-control" v-model="deptDetailData.standardDeptId" :disabled="eventOrg">
                                                    <option v-for="item in standardDeptList" value="{{item.stardardDeptId}}">{{item.stardardDeptName}}</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">中西标志</label>
                                            <div class="col-md-7">
                                                <select name="zxFlag" class="form-control" v-model="deptDetailData.zxFlag" :disabled="eventOrg">
                                                    <option value="1">中医</option>
                                                    <option value="0">西医</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">重点科室</label>
                                            <div class="col-md-7">
                                                <select name="inpormtant" class="form-control" v-model="deptDetailData.inpormtant" :disabled="eventOrg">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">门诊使用</label>
                                            <div class="col-md-7">
                                                <select name="outpatientUse" class="form-control" v-model="deptDetailData.outpatientUse" :disabled="eventOrg">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">住院使用</label>
                                            <div class="col-md-7">
                                                <select name="inpatientUse" class="form-control" v-model="deptDetailData.inpatientUse" :disabled="eventOrg">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">病区使用</label>
                                            <div class="col-md-7">
                                                <select name="inpatientPlaceUse" class="form-control" v-model="deptDetailData.inpatientPlaceUse" :disabled="eventOrg">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">医技使用</label>
                                            <div class="col-md-7">
                                                <select name="technologyUse" class="form-control" v-model="deptDetailData.technologyUse" :disabled="eventOrg">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">其他使用</label>
                                            <div class="col-md-7">
                                                <select name="otherUse" class="form-control" v-model="deptDetailData.otherUse" :disabled="eventOrg">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">门诊位置</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" placeholder="门诊位置" name="outPatientAddr" v-model="deptDetailData.outPatientAddr" :disabled="eventOrg" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">住院位置</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" placeholder="病房位置" name="inPatientAddr" v-model="deptDetailData.inPatientAddr" :disabled="eventOrg" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">联系电话</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" placeholder="联系电话" name="contactNo" v-model="deptDetailData.contactNo" :disabled="eventOrg" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">Email</label>
                                            <div class="col-md-7">
                                                <input type="text" class="form-control" placeholder="邮件地址" name="email" v-model="deptDetailData.email" :disabled="eventOrg" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3"><span class="start">*</span>科室介绍</label>
                                            <div class="col-md-7">
                                                <textarea id="description" name="description" class="form-control depDescription" rows="3" placeholder="科室介绍" v-model="deptDetailData.description" :disabled="eventOrg"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-actions clearfix fluid ele-hide">
                                            <div class="col-md-offset-3 col-md-7">
                                                <button type="button" class="btn btn-default save-btn" @click="confirmUpdateDeptEvent" :disabled="eventOrg">提 交</button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </aside>
                    </div>
                </div>
                <!-- /.modal-dialog -->
                <!-- 信息填写不完整 -->
                <div id="nomess" class="modal fade msg-without-complete" tabindex="-1" role="dialog">
                    <div class="modal-dialog modal-sm" role="document">
                        <div class="modal-content">
                            <span v-text="subErrorMsg"></span>
                        </div>
                    </div>
                </div>
                <!--msg-not-complete-->
            </div>
        </div>
        <!-- 删除提示 -->
        <div id="delCoverTips" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">删除</h4>
                    </div>
                    <div class="modal-body">
                        <p class="del-tips">您确定要删除"<span class="del-dep" v-text="deleteDepName"></span>"吗？</p>
                    </div>
                    <div class="modal-footer">
                        <div class="form-group">
                            <button id="confirmDelBtn" class="save-btn" type="button">确认</button>
                            <button type="button" class="cancel-btn" data-dismiss="modal">取消</button>
                        </div>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
        <div id="rMenu">
            <ul>
                <li id="m_add" @click="addTreeNode();">新增下级</li>
                <li id="m_del" @click="removeTreeNode();">删除</li>
            </ul>
        </div>
    </div>
</template>
<script>
import 'assets/reset.css';
import 'assets/lib/bootstrap-3.3.2/css/bootstrap.min.css';
import 'assets/lib/bootstrap-3.3.2/js/bootstrap.min.js';

//ztree
import 'assets/lib/zTree/img/metro.gif';
import 'assets/lib/zTree/img/metro.png';
import 'assets/lib/zTree/img/line_conn.png';

import 'assets/lib/zTree/metroStyle.css';
import 'assets/lib/zTree/js/jquery.ztree.core.js';
import 'assets/lib/zTree/js/jquery.ztree.excheck.min.js';
import 'assets/lib/zTree/js/jquery.ztree.exedit.min.js';
import 'assets/lib/zTree/js/jquery.ztree.exhide.min.js';

import Header from 'components/module-head.vue';
import Asider from 'components/menu-list.vue';
import footerPage from 'components/BootPage.vue';
import Public from 'assets/public.js';
export default {
    data() {
            return {
                //科室详情数据
                deptDetailData: {
                    deptId: "",
                    deptName: "", //科室名称
                    localId: "", //上级科室Id
                    technologyUse: "", //医技使用
                    deptType: "01", //科室类型,base_departmentType
                    outpatientUse: "", //门诊使用
                    inpormtant: "", //重点科室标签
                    orgId: "",
                    standardDeptId: "", //标注科室id
                    inpatientPlaceUse: "", //病区使用
                    email: "", //
                    description: "", //描述
                    otherUse: "", //其他使用
                    contactNo: "", //联系电话
                    outPatientAddr: "", //门诊位置
                    localDeptId: "", //科室代码
                    inPatientAddr: "", //住院位置
                    zxFlag: "", //中西标志,0西医 1中医
                    inpatientUse: "", //住院使用
                    localOrgId: "" //医院代码
                },

                //字典请求
                dictionary: {
                    deptType: {}, //科室类型base_departmentType
                },

                //标准科室
                standardDeptList: {},

                //社区机构列表数据（分页传递）
                orgListData: {},
                //信息填写不完善
                subErrorMsg: '',
                //被删除科室的--名称
                deleteDepName: '',

                //科室标识
                // nodeleid: 'dept',
                //上级科室
                prevDept: '无',
                //父节点（机构）
                rootName: '',
                //缓存科室代码
                // cacheDeptCode: '',
                //缓存科室id
                cacheDeptId: '',

                // //缓存treeNode
                // cacheTreeNode: {},
                //是否触发机构点击
                eventOrg: 'disabled'
            }
        },
        ready() {
            //初始化科室列表
            this.ztreeEvent();
            //标准科室
            this.standardDeptEvent();
            //字典请求
            this.dictionaryRequest();
        },
        components: {
            //头部组件
            'header-component': Header,
            //侧部导航组件
            'aside-component': Asider,
            'bootpage-component': footerPage
        },
        methods: {
            //医院列表文件树
            ztreeEvent() {
                    var that = this;
                    var setting = {
                        async: {
                            enable: true,
                            type: "post",
                            url: Public.MENU_URL(),
                            dataType: "JSON",
                            headers: {
                                "X-Access-Token": sessionStorage.getItem('accessToken'),
                                "X-Service-Id": "base.sysDepartmentService",
                                "X-Service-Method": 'queryDeptList',
                                "Content-Type": "application/json"
                            },
                            autoParam: ["id", "nodeType=nodeType", "level"],
                            dataFilter: ajaxDataFilter
                        },
                        callback: {
                            // beforeDrag: beforeDrag,
                            // beforeRemove: beforeRemove,
                            // onRemove: zTreeOnRemove,
                            onRightClick: OnRightClick,
                            onClick: zTreeOnClick
                        }
                    };
                    //赋值
                    function ajaxDataFilter(treeId, parentNode, responseData) {
                        responseData = responseData.body;
                        $.each(responseData, function(index, el) {
                            el.isParent = true;
                            el.nodeType = "dept";
                        })
                        return responseData;
                    };
                    //左击
                    function zTreeOnClick(event, treeId, treeNode, msg) {
                        console.log(treeNode);
                        var zTree = $.fn.zTree.getZTreeObj("hospitalLists");
                        var deptIdds = treeNode.id;
                        that.rootName = treeNode.orgName;
                        //获取父元素parentid
                        let sNodes = zTree.getSelectedNodes();
                        console.log(sNodes);
                        let node = sNodes[0].getParentNode();
                        if (treeNode.nextNodeType == 'org') {

                            // that.deptDetailData.deptName = '';
                            // that.deptDetailData.localDeptId = '';
                            // that.deptDetailData.deptType = '';
                            // that.deptDetailData.description = '';
                            that.clearBindDataEvent();
                            that.eventOrg = 'disabled';
                        } else {
                            that.eventOrg = false
                        }
                        if (sNodes.length > 0 && node != null) {
                            // var nodes = zTree.getNodesByParam("id", "test", null);

                            $.ajax({
                                type: "post",
                                url: Public.MENU_URL(),
                                dataType: "JSON",
                                headers: {
                                    "X-Access-Token": sessionStorage.getItem('accessToken'),
                                    "X-Service-Id": "base.sysDepartmentService",
                                    "X-Service-Method": 'getDept',
                                    "Content-Type": "application/json"
                                },
                                data: '["' + deptIdds + '"]',
                                success: function(ressult) {
                                    that.deptDetailData = ressult.body
                                }
                            });
                        };
                        if (treeNode.level == 1) {
                            that.prevDept = '无';
                        } else {
                            let nodeparent = zTree.getNodeByTId(treeNode.parentTId);
                            console.log(nodeparent);
                            if (nodeparent) {
                                that.prevDept = nodeparent.name;
                            }
                        }
                    }
                    //右击
                    function OnRightClick(event, treeId, treeNode) {
                        var treeObj2 = $.fn.zTree.getZTreeObj("hospitalLists");
                        console.log(treeNode)
                        that.rootName = treeNode.orgName;
                        that.deptDetailData.orgId = treeNode.orgId;
                        if (treeNode.level == 0) {
                            that.cacheDeptId = '';
                            that.deptDetailData.localId = '';
                            that.eventOrg = 'disabled';
                            that.showRMenu("root", event.clientX, event.clientY);
                        } else {
                            that.eventOrg = false;
                            that.showRMenu("node", event.clientX, event.clientY);
                            that.prevDept = treeNode.name;
                            that.cacheDeptId = treeNode.id;
                            // that.deptDetailData.localId = treeNode.localId;
                            that.deptDetailData.localDeptPid = treeNode.localId;
                        }
                        treeObj2.selectNode(treeNode);
                    }
                    var code, log, className = "dark";

                    //删除节点前操作
                    function beforeRemove(treeId, treeNode) {
                        $('#delCoverTips').modal('show');
                        that.deleteDepName = treeNode.text;
                        // operaDel(treeId, treeNode);
                        return false;
                    }

                    //显示删除按钮
                    function showRemoveBtn(treeId, treeNode) {
                        if (treeNode.pid == "#" || treeNode.pid == null || treeNode.pid == "") {
                            return false;
                        } else {
                            return true;
                        }
                        //return !treeNode.isParent;
                    }
                    //禁止拖拽
                    function beforeDrag(treeId, treeNodes) {
                        return false;
                    }

                    function removeHoverDom(treeId, treeNode) {
                        $("#addBtn_" + treeNode.tId).unbind().remove();
                    };
                    $(document).ready(function() {
                        $.fn.zTree.init($("#hospitalLists"), setting);
                    });
                },

                //字典请求
                dictionaryRequest() {
                    var that = this;
                    var arr = ["base.dictionary.base_departmentType"];
                    $.when(Public.commonajax('coms.multipleDictionaryService', 'findDic', '[' + JSON.stringify(arr) + ']')).done((res) => {
                        $.each(res.body, (index, ele) => {
                            if (arr[0] == ele.dicId) {
                                that.dictionary.deptType = ele.items
                            };
                        });
                    });
                },

                //标准科室
                standardDeptEvent() {
                    var that = this;
                    $.when(Public.commonajax('base.sysDepartmentService', 'getStandardDeptList', '["' + '"]')).done((res) => that.standardDeptList = res.body);
                },


                //右键菜单部分
                showRMenu(type, x, y) {
                    $("#rMenu ul").show();
                    if (type == "root") {
                        $("#m_del").hide();
                        $("#m_add").show();
                    } else if (type == "noadd") {
                        $("#m_del").show();
                        $("#m_add").hide();

                    } else {
                        $("#m_del").show();
                        $("#m_add").show();

                    }
                    $("#rMenu").css({
                        "top": y + "px",
                        "left": x + "px",
                        "visibility": "visible"
                    });

                    $("body").bind("mousedown", this.onBodyMouseDown);
                },

                hideRMenu() {
                    $("#rMenu").css({
                        "visibility": "hidden"
                    })
                    $("body").unbind("mousedown", this.onBodyMouseDown);
                },

                onBodyMouseDown(event) {
                    if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length > 0)) {
                        $("#rMenu").css({
                            "visibility": "hidden"
                        });
                    }
                },


                //清空绑定数据
                clearBindDataEvent() {
                    this.deptDetailData.deptId = '';
                    this.deptDetailData.deptName = '';
                    // this.deptDetailData.localId = '';
                    this.deptDetailData.technologyUse = '';
                    this.deptDetailData.deptType = '';
                    this.deptDetailData.outpatientUse = '';
                    this.deptDetailData.inpormtant = '';
                    this.deptDetailData.standardDeptId = '';
                    this.deptDetailData.inpatientPlaceUse = '';
                    this.deptDetailData.email = '';
                    this.deptDetailData.description = '';
                    this.deptDetailData.otherUse = '';
                    this.deptDetailData.contactNo = '';
                    this.deptDetailData.outPatientAddr = '';
                    this.deptDetailData.localDeptId = '';
                    this.deptDetailData.inPatientAddr = '';
                    this.deptDetailData.zxFlag = '';
                    this.deptDetailData.inpatientUse = '';

                    // this.deptDetailData.localOrgId = '';
                },


                //添加科室
                addTreeNode() {
                    this.clearBindDataEvent();
                    this.hideRMenu();
                    this.eventOrg = false;
                },

                //确认--新增/修改（更新）科室
                confirmUpdateDeptEvent() {
                    var that = this;
                    let flags = this.validationData();
                    if (flags != false) {
                        $.when(Public.commonajax('base.sysDepartmentService', 'saveDept', '[' + JSON.stringify(this.deptDetailData) + ']')).done(function(res) {
                            $('.msg-without-complete').modal('show');
                            if (res.code == 200) {
                                // that.ztreeEvent();

                                var treeObj = $.fn.zTree.getZTreeObj("hospitalLists");
                                if (that.deptDetailData.deptId != '') {
                                    treeObj.getSelectedNodes()[0].name=that.deptDetailData.deptName;

                                    treeObj.updateNode(treeObj.getSelectedNodes()[0]);
                                // let nodeparent = treeObj.getNodeByTId(treeObj.getSelectedNodes()[0].parentTId);
                                //    treeObj.reAsyncChildNodes(nodeparent, "refresh");//
                                   //修改的时候更新父节点的所有子节点
                                } else {
                                    treeObj.reAsyncChildNodes(treeObj.getSelectedNodes()[0], "refresh");//新增的时候直接更新选中节点的子节点
                                    // treeObj.updateNode(treeObj.getSelectedNodes()[0]);
                                }
                                that.subErrorMsg = "操作成功!";
                            } else {
                                that.subErrorMsg = res.msg;
                            };
                            setTimeout(() => $('.msg-without-complete').modal('hide'), 1500);
                        });
                    } else {
                        setTimeout(() => {
                            $('.msg-without-complete').modal('hide');
                            return false
                        }, 1800)
                    };
                },

                //删除科室
                removeTreeNode() {
                    var that = this;
                    this.hideRMenu();
                    var delAjax = $.ajax({
                        type: "post",
                        url: Public.MENU_URL(),
                        dataType: "JSON",
                        headers: {
                            "X-Access-Token": sessionStorage.getItem('accessToken'),
                            "X-Service-Id": "base.sysDepartmentService",
                            "X-Service-Method": 'deleteDepartment',
                            "Content-Type": "application/json"
                        },
                        data: '["' + this.cacheDeptId + '"]'
                    });
                    $.when(delAjax).done(function(res) {
                        if (res.code == 200) {
                            var delObj = $.fn.zTree.getZTreeObj("hospitalLists");
                            delObj.removeNode(delObj.getSelectedNodes()[0]);
                            that.clearBindDataEvent();
                            // let nodeparent = delObj.getNodeByTId(delObj.getSelectedNodes()[0].parentTId);
                            //        delObj.reAsyncChildNodes(nodeparent, "refresh");//
                                   //修改的时候更新父节点的所有子节点
                            // delObj.reAsyncChildNodes(null, "refresh");
                            that.subErrorMsg = "删除成功!";
                             that.prevDept="";
                            $('#nomess').modal('show');
                            setTimeout(function() {
                                $('.msg-without-complete').modal('hide');
                            }, 1500);
                        } else {
                            that.subErrorMsg = res.msg;
                            $('#nomess').modal('show');
                            setTimeout(function() {
                                $('.msg-without-complete').modal('hide');
                            }, 1500);
                        }
                    });
                },

                //验证
                validationData() {
                    $('.msg-without-complete').modal('show');
                    //必填验证
                    let name = this.deptDetailData.deptName;
                    let code = this.deptDetailData.localDeptId;
                    let type = this.deptDetailData.deptType;
                    let dscp = this.deptDetailData.description;
                    let code_exp = /^[0-9a-zA-Z]+$/;
                    if (name == '') {
                        this.subErrorMsg = "请填写科室名称!";
                        return false
                    }
                    if (code_exp.test(code) != true) {
                        this.subErrorMsg = "科室代码只能为数字或字母!";
                        return false
                    }
                    if (type == '') {
                        this.subErrorMsg = "请选择科室类型!";
                        return false
                    }
                    if (dscp == '') {
                        this.subErrorMsg = "请填写科室介绍!";
                        return false
                    }
                    //选择性验证
                    let telp = this.deptDetailData.contactNo;
                    let email = this.deptDetailData.email;
                    let telp_exp = /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/;
                    let email_exp = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
                    if (telp != '') {
                        if (telp_exp.test(telp) != true) {
                            this.subErrorMsg = "电话号码格式不正确!";
                            return false
                        }
                    }
                    if (email != '') {
                        if (email_exp.test(email) != true) {
                            this.subErrorMsg = "邮箱格式不正确!";
                            return false
                        }
                    }
                }

        } //methods
}
</script>
